<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" th:href="@{/center/lib/layui-v2.5.5/css/layui.css}" media="all">
		<link rel="stylesheet" th:href="@{/center/css/public.css}" media="all">
		<script th:src="@{/center/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
		<script th:src="@{/center/js/lay-config.js}" charset="utf-8"></script>
		<script>
			layui.use(['form', 'layarea'], function() {
				var form = layui.form,
					layer = layui.layer,
					layarea = layui.layarea,
					$ = layui.$;
		
				//渲染地区三级联动
				layarea.render({
					elem: '#area-picker',
					change: function(res) {
						//选择结果
						console.log(res);
					}
				});
		
		
				//修改地址确认
				$('#addrChange').click(function() {
					var newAddr = $("#province").val() + $("#city").val() + $("#county").val() + $("#street").val();
					$("#communityAddr").val(newAddr);
					return false;
				});
		
				//监听提交
				form.on('submit(saveBtn)', function(data) {
					$.ajax({
						url: '/center/editForum',
						method: 'POST',
						contentType: 'application/json;charset=utf-8',
						data: JSON.stringify(data.field),
						success: function(res) {
							if (res.msg === '本次更新了：') {
								layer.msg(res.msg + res.count + '条记录', {
									icon: 1,
									time: 1000 //1秒关闭（如果不配置，默认是3秒）
								}, function() {
									// var iframeIndex = parent.layer.getFrameIndex(window.name);
									// parent.layer.close(iframeIndex);
									parent.document.location.reload();
								});
		
							} else {
								layer.alert(res.msg);
							}
		
						}
					});
		
		
					return false;
				});
			});
		</script>
		<style>
			body {
            background-color: #ffffff;
        }
    </style>
	</head>
	<body>
		<form class="layui-form layuimini-form">
			<blockquote class="layui-elem-quote">社区信息
				<div class="layui-form-item">
					<label class="layui-form-label">社区名称:</label>
					<div class="layui-input-block">
						<input type="text" name="communityName" placeholder="请填写社区名称" class="layui-input" lay-verify="required" id="communityName">
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label">社区电话:</label>
					<div class="layui-input-block">
						<input type="text" name="communityTel" id="communityTel" placeholder="请填写社区电话" value="" class="layui-input"
						 lay-verify="number" required maxlength="11">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">社区地址:</label>
					<div class="layui-input-block">
						<input type="text" name="communityAddr" id="communityAddr" placeholder="" value="" class="layui-input" readonly="readonly"
						 style="color: gray;">
					</div>
				</div>


			</blockquote>
			<blockquote class="layui-elem-quote layui-quote-nm">

				<div class="layui-form-item" id="area-picker">
					<div class="layui-form-label">地址选择:</div>
					<div class="layui-input-block">
						<select name="province" id="province" class="province-selector" data-value="四川省" lay-filter="province-1">
							<option value="">请选择省</option>
						</select>
					</div>
					<div class="layui-input-block">
						<select name="city" id="city" class="city-selector" data-value="" lay-filter="city-1">
							<option value="">请选择市</option>
						</select>
					</div>
					<div class="layui-input-block">
						<select name="county" id="county" class="county-selector" data-value="" lay-filter="county-1">
							<option value="">请选择区</option>
						</select>
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label">社区街道:</label>
					<div class="layui-input-block">
						<input type="text" name="street" id="street" placeholder="请填写社区街道" class="layui-input">
					</div>
				</div>
				<hr class="layui-bg-gray">

				<input type="hidden" id="communityId" name="communityId"><!-- 隐藏字段用于给后端传值 -->
				<button class="layui-btn layui-btn-normal" id="addrChange">确认修改社区地址</button>

				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">提交并退出</button>
				<span style="color: gray">&emsp;如果需要修改社区地址需同时修改省市区和社区街道信息&emsp;</span>
			</blockquote>

		</form>

	</body>
</html>
